This application is intended to demonstrate Crimson Basic being used to provide a simple Customer file maintenance program. Is shows how GUI applications are programmed to respond to user events (event driven) as opposed to the data driven programming method used in non-GUI applications.
Try using the program to gain an understanding of the actions which are performed in response to user events before reading further.
The CUSTFORM Form.
Custform uses Editable Text controls for the majority of the fields within the form with a set of Radio Buttons for the Location. Note that the Enabled property of the CUSTNO control is set to false as the user is never allowed to change this field.
Six Button controls to the bottom right of the form allow the user to control the actions performed.
The LOCATEFORM Form.
The LocateForm, at first appearance, looks like an empty form. By clicking and dragging the centre of the form you will see that a List Box is present which covers the whole displayable area of the form.
The Form itself is set to be invisible as it is to be displayed only upon user command.
The 'Initial' program module.
The Initial module is executed at program start-up to perform all actions necessary before the first form is displayed.
The disk file "CustomerFile" is opened in RANDOM mode with a record length of 366, which is the length of the CustStruct structure. (see the definition of this in the Common module).
The LocateForm form is opened (but is invisible and will not be seen). It is opened at this stage as a form needs to be open before any controls which it contains can be manipulated.
The Read_File procedure in the Common module is called to read the contents of the file and populate the List Box within LocateForm.
The CustForm form is opened and populated with the first record in the file.
The 'Common' module.
The Read_File procedure reads each record from the file sequentially and inserts a row in the LocateForm List Box for each. This will be used to allow the user to select any record from within the file.
The end-of-file condition is detected by testing for a non-zero value in the ERR variable.
The 'CustFrmCode' module.
The NxtBtn.Click procedure is invoked when the user presses the 'Next' button. The Current Record pointer is incremented and the Populate_Custform function called to populate the form. If we have passed the end-of-file, them Populate_Custform will return False and no further action is taken.
The PrevBtn.Click procedure moves the Current Record pointer back one record and displays that record.
The AddBtn.Click routine provides different functions depending upon the current mode within the program (determined by the Mode variable).
If this button is pressed in Query mode (mode={Q}) then the form fields are blanked, the caption on the Add and Update buttons set to 'Save' and 'Cancel' respectively, and the rest of the buttons disabled.
If in Add mode, (the button Caption displays 'Save'), a new record is added to the file containing the values input by the user. The new row is inserted into the LocateForm List Box.
If in Update mode, the current record is updated with the values supplied by the user.
The corresponding row in the LocateForm List Box is updated accordingly.
The UpdateBtn.Click procedure has 2 roles:
When in Query mode (the button caption is set to 'Update'), the Captions on the AddBtn and UpdateBtn are set to 'Save' and 'Cancel" and all other buttons are disabled.
Otherwise (the button caption is set to 'Cancel'), the buttons are restored to their original condition and no further action is taken.
The LocateBtn.Click procedure makes LocateForm visible allowing the user to make a selection.
The QuitBtn.Click procedure closes the file and exits the program.
The Populate_Custform function reads the file record into the CustStruct structure, using the record number supplied in the RecNo parameter.
If the ERR variable is set then the record in question does not exist (before the start-of-file or after the end-of-file).
Each control within the form is updated in turn with the values from the CustStruct structure.
The Update_Record procedure updates the CustStruct structure with values from the form and writes the record to disk using the PUT command.
The 'LocFrmCode' module.
The LocateForm.OnClose procedure is invoked when the user clicks on the Close Box on the LocateForm form. In this case we wish to perform the same function as if the user had double clicked the List Box so therefore we call the LBox.DClick procedure.
The LBox.DClick procedure searches to find which List Box row has been selected (if any) using the GetSelected method.
If a row has been selected, the form is populated with the values contained in the corresponding record.
Note that the position of a row within the List Box is equivalent to the Record number of the corresponding record within the file.
After selecting a record, the LocateForm form is hidden.